<?php

require dirname(__FILE__).'/config.inc.php';

if( false == defined('HOST') ) {
	header('Location: install/');
	exit;
}

// menu items - will secure request var [ section ] latter
$menuItems = array (

	// MENU ITEMS HERE
	// 'menuitem' => 'Menu item label',
	// this will need the file cont-menuitem.inc.php
	
	// don't remove this
	lang::translate('men_admin_settings')=>array (
		'_adm_users' => lang::translate('men_users'),
		'_adm_locations' => lang::translate('locations'),
		'_adm_specialist_field' => lang::translate('specialists_fields'),
		'_adm_careers' => lang::translate('careers'),
		'_adm_companies' => lang::translate('companies'),
		'_adm_suppliers' => lang::translate('suppliers'),
		'_adm_professionals' => lang::translate('professionals')
	)
);

// cache menu in session
$_SESSION['menu_items'] = $menuItems;

// send requests and create the instance
$a = new admin( $_SERVER['REQUEST_URI'], isset($_POST) ? $_POST : array(), isset($_FILES) ? $_FILES : array() );

// define your current section
if(!isset($_GET['section'])) {
	$_GET['section'] = '_default';
}

// validate GET from menu array, to make a safe include
if( $a->validateInclude( $_GET['section'] ) && is_file(dirname(__FILE__).'/cont-'.$_GET['section'].'.inc.php') ) {
	require dirname(__FILE__).'/cont-'.$_GET['section'].'.inc.php';
} else {
	die('This is not a valid section! Make sure the file "cont-'.htmlentities($_GET['section']).'.inc.php" exists.');
}

// initialize
$a->build();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><?php echo lang::translate('_site_title_') ?> - <?php echo $a->show ?> <?php echo $a->section ? ' : ' . $a->section : '' ?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="language" content="en" />
	
	<base href="<?php echo BASE_URL ?>" />
	
	<script type="text/javascript">
		var DICT_SEARCH_FILTER_TO = '<?php echo str_replace("'", '"', lang::translate('js_search_filter_to')) ?>';// 'Select field to filter by... &nbsp;';
		var DICT_REMOVER_FILTER = '<?php echo str_replace("'", '"', lang::translate('js_remove_filter')) ?>';// 'Remove filter';
		var DICT_CHOOSE_A_FILTER = '<?php echo str_replace("'", '"', lang::translate('js_choose_a_filter')) ?>';// 'choose a field';
		var DICT_SET_SOME_VALID_FILTERS = '<?php echo str_replace("'", '"', lang::translate('js_set_some_filters')) ?>';// 'Please set some valid filters!';
		var DICT_SELECT_RECORDS_TO_DELETE = '<?php echo str_replace("'", '"', lang::translate('js_select_records_to_delete')) ?>';
		var DICT_DELETE_SELECTED_RECORDS = '<?php echo str_replace("'", '"', lang::translate('js_delete_selected_recs')) ?>';
	</script>

	<link rel="stylesheet" type="text/css" href="jscss/css.css" />
	<link rel="stylesheet" type="text/css" href="jscss/jquery_ui.css" />
	<script type="text/javascript" src="jscss/jquery_and_ui.js"></script>
	<script type="text/javascript" src="jscss/js.js"></script>
	
</head>

<body>

	<table class="main">
		<?php if($a->navigation) { ?>
		<tr>
			<td colspan="2" class="_header">
				<p id="userArea">
					<span id="userInfo">
						<img src="<?php echo $a->USER->userData['avatar'] ?>" alt="" id="avatar" />
						<?php echo lang::translate('welcome_message') ?> <strong><?php echo $a->h(isset($_SESSION['USERAUTH']['username'])?$_SESSION['USERAUTH']['username']:'&nbsp;') ?></strong>!
						<br /><span style="font-size:11px"><?php echo date('d M Y H:i') ?></span>
					</span>
					<?php echo $a->userOptions ?>
				</p>
				<h1>
					<a href="./"><?php echo lang::translate('_site_title_') ?></a>
					<a href="./" onclick="return toggleMenu()"><img style="margin:0 0 -2px 0" src="<?php echo BASE_URL ?>images/icons/togglemenu.png" alt="<?php echo lang::translate('toggle_menu') ?>" title="<?php echo lang::translate('toggle_menu') ?>" class="tt" /></a>
				</h1>
			</td>
		</tr>
		<?php } ?>
		<tr>
			<?php if($a->navigation) { ?>
				<td class="_menu" id="_menu" valign="top"><?php
					echo $a->generateMenu();
				?></td>
			<?php } ?>
			<td class="_content" valign="top"><?php
			
				// some free text before
				echo '<p style="clean:both">&nbsp;</p>'.$a->textBefore;
			
				// get top buttons
				echo $a->actionButtons;
				
				// success message
				if( $a->success ) {
					echo '<div id="successMessage">' . $a->success . '</div>';
				}
				
				// if error, show
				if(!empty($a->error)) {
					echo '<p class="_error">' . $a->error . '</p>';
				}
				
				// create filter DIV
				echo '
					<div id="_filterZone">'.$a->filtersFrontEnd.'</div>
					<p id="_submitFilters">
						<a href="#" id="_applyFilters" onclick="return applyCurrentFilters()">'.lang::translate('apply_filters').'</a>
						<a href="#" id="_applyFilters_fake" onclick="return false">'.lang::translate('wait').'</a>
					</p>
				';

				// add help text if not empty
				if( !empty($a->help) ) {
					echo '<div id="helpDiv"'.( $a->showHelp ? '' : ' style="display:none"' ).'>'.$a->help.'</div>';
				}
				
				// for (insert or update)
				echo $a->form;
				
				// listing
				echo $a->listTable;
				
				// some free text after
				echo $a->textAfter;
				
				// pages
				echo $a->listPages;
				
			?></td>

		</tr>
	</table>

	<?php
	// if we have content fields, show tinyMCE
	if($a->haveFieldType('content') && ( $a->show == 'insert' || $a->show == 'update' ) ) {
		$content_fields = '';
		foreach($a->fields as $field=>$options) {
			if($options['type'] == 'content') {
				$content_fields .= $field.',';
			}
		} $content_fields = substr($content_fields, 0, -1);
		?>
		<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript">
			tinyMCE.init({
				mode : 'exact', elements : '<?php echo $content_fields ?>', theme : 'advanced',
				plugins : 'save,paste,table,style,advimage,advlink,fullscreen,media,template', /* imagemanager, */ 
				entity_encoding: "raw", relative_urls:false, convert_urls:false, content_css:'jscss/css_editor.css',
				theme_advanced_toolbar_location:"top", theme_advanced_statusbar_location: "bottom", theme_advanced_resizing : true,
				theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,sub,sup,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,formatselect,fontselect,fontsizeselect',
				theme_advanced_buttons2 : 'pastetext,pasteword,undo,redo,|,link,image,media,charmap,|,tablecontrols,|,fullscreen,code,styleselect',
				language: "en", theme_advanced_buttons3 : '', theme_advanced_buttons4 : '', external_image_list_url : '' /* you can have a PHP here to get a simple file manager */
			});
		</script>
	<?php } ?>

	<script type="text/javascript">
		var availableFilters = <?php echo $a->generateJSONAvailableFilters() ?>;
		var currentURL = '<?php echo $a->url(false, '&') ?>';
	</script>
	<script type="text/javascript" src="jscss/after.js"></script>
	
</body>

</html>
